//
//  MyCloudController.swift
//  EyeVisionForPatients
//
//  Created by PMC on 2020/2/28.
//  Copyright © 2020 tao Tao. All rights reserved.
//

import UIKit

class MyCloudController: BaseViewController {
    
    private var status: Int
    
    init(with status: Int) {
        self.status = status
        super.init(nibName: nil, bundle: nil)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupPageStyle()
    }
}

extension MyCloudController {
    private func setupPageStyle() {
        var style = PageViewStyle()
        style.isTitleScaleEnabled = true
        style.titleSelectedColor = .mainColor
        style.titleNormalColor = .textGray
        style.isContentViewScrollEnabled = true
        style.titleFont = .medium(14)
        
        let titles = ["全部", "待支付", "未开始", "进行中", "待评价", "已取消", "已完成"]
        
        var vcs = [UIViewController]()
        for i in 0..<titles.count {
            let index = i != 6 ? i : 7
            let status = OrderStatus(rawValue: index) ?? .all
            let cloudOrderVc = MyCloudOrderController(with: status)
            vcs.append(cloudOrderVc)
        }
        
        for vc in vcs {
            self.addChild(vc)
        }
        let rect = CGRect(x: 0, y: 0, width: screenW, height: screenH - navBarH - 44)
        let pageView = PageView(frame: rect,
                                style: style,
                                titles: titles,
                                childViewControllers: vcs,
                                startIndex: status)
        view.addSubview(pageView)
    }
}
